package com.wxw.BaseLibrary.tool;

import android.content.Context;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class ConnectivityMgr {
    public static boolean mobileEnabled(Context context) {
        return getNetworkStatus(context, ConnectivityManager.TYPE_MOBILE);
    }

    public static boolean wifiEnabled(Context context) {
        return getNetworkStatus(context, ConnectivityManager.TYPE_WIFI);
    }

    public static boolean getNetworkStatus(Context context, int type) {
        ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getNetworkInfo(type);
        if (info != null) {
            return info.isAvailable();
        }
        return false;
    }

    public static int getActiveNetworkType(Context context) {
        ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        if (info != null) {
            return info.getType();
        }
        return -1;
    }

    public static boolean gpsEnabled(Context context) {
        LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
        boolean gps = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
        boolean network = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        if (gps || network) {
            return true;
        }
        return false;
    }

    public static boolean networkLocationEnabled(Context context) {
        LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
        boolean network = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        return network;
    }
}
